#!/bin/bash
# 构建 Docker 镜像，命名为 docker-demo:1.0
echo "Building Docker image..."
docker build -t docker-demo:1.0 .

# 可选：如果需要从特定目录构建镜像，可以取消注释下面这行，并修改路径
# docker build -t docker-demo:1.0 /data/demo

# 运行容器
echo "Running the container..."
docker run -d --name dd -p 8080:8080 -p 8090:8090 docker-demo:1.0

# 等待容器启动
echo "Waiting for the container to start..."
sleep 5

# 查看容器状态
echo "Checking running containers..."
docker ps

# 访问服务
echo "Accessing the service..."
curl localhost:8080/hello/count
echo ""

# 删除服务部分
echo "Deleting the service..."

# 停止并移除容器
echo "Stopping and removing the container..."
docker rm -f dd

# 移除 Docker 镜像
echo "Removing the Docker image..."
docker rmi docker-demo:1.0

echo "Service deleted."
